﻿namespace BloodlustFury.DataMiner.Business
{
	#region "Using Statements"

	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Text;

	#endregion

	public class TestModule : Module
	{
		#region "Private Member Variables"

		Double absoluteError = -1f;

		Double relativeError = -1f;

		Double percentError = -1f;

		Double predictedNumberFaults;

		#endregion

		#region "Constructors"
		
		public TestModule()
		{
			this.PredictedNumberFaults = -1;
			this.NearestNeighbors = new List<Double>();
		}

		#endregion

		#region "Public Properties"

		public List<Double> NearestNeighbors
		{
			get;
			set;
		}

		public Double PredictedNumberFaults
		{
			get { return Math.Round(this.predictedNumberFaults, 2); }

			set { this.predictedNumberFaults = value; }
		}

		public Double AbsoluteError 
		{ 
			get 
			{
				if (this.absoluteError == -1 && PredictedNumberFaults != -1 && Y != -1)
				{
					this.absoluteError = Math.Abs(this.Y - this.PredictedNumberFaults);
				}

				return Math.Round(this.absoluteError, 2);
			}
		}

		public Double RelativeError 
		{ 
			get
			{
				if (this.relativeError == -1 && PredictedNumberFaults != -1 && Y > 0)
				{
					this.relativeError = Math.Abs(this.Y - this.PredictedNumberFaults) / Math.Abs(this.Y);
				}
				else if (Y == 0)
				{
					this.relativeError = 0;
				}

				return Math.Round(this.relativeError, 2);
			}
		}

		public Double PercentError
		{
			get
			{
				if (this.percentError == -1 && PredictedNumberFaults != -1 && Y > 0)
				{
					this.percentError = 100 * Math.Abs(this.Y - this.PredictedNumberFaults) / Math.Abs(this.Y);
				}

				else if (Y == 0)
				{
					this.percentError = 0;
				}

				return Math.Round(this.percentError, 2);
			}
		}

		internal void ResetErrors()
		{
			this.absoluteError = -1f;
			this.relativeError = -1f;
			this.percentError = -1f;
		}

		#endregion
	}
}
